package com.example.treelistviewdemo;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ExpandableListView;
import entity.CategoryItemTreeView;
import entity.PaperItemTreeViewData;

public class MainActivity extends Activity {

	private ExpandableListView mExpandableListView;
	private List<PaperItemTreeViewData> mGroupCollection;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		prepareResource();
		initPage();
	}

	private void prepareResource() {

		mGroupCollection = new ArrayList<PaperItemTreeViewData>();

		for (int i = 1; i < 6; i++) {
			PaperItemTreeViewData mPaper = new PaperItemTreeViewData();
			mPaper.Name = "Paper" + i;
			mPaper.IsChoose = true;
			for (int j = 1; j < 5; j++) {
				CategoryItemTreeView mCategory = new CategoryItemTreeView();
				mCategory.Name = "Category " + j;
				mCategory.IsChoose = true;
				mPaper.ListCategory.add(mCategory);
			}

			mGroupCollection.add(mPaper);
		}

	}

	private void initPage() {
		mExpandableListView = (ExpandableListView) findViewById(R.id.expandableListView);
		ExpandableListAdapter adapter = new ExpandableListAdapter(this,
				mExpandableListView, mGroupCollection);
		mExpandableListView.setAdapter(adapter);
	}
}